package com.vzoom.logdesensitization.strategyimpl;

import com.vzoom.logdesensitization.DesensitizationStrategy;
import com.vzoom.logdesensitization.util.StarUtil;

public class EmailDesensitizationStrategy implements DesensitizationStrategy {
    @Override
    public String desensitization(Object origin) {
        String toString = String.valueOf(origin);
        if (origin == null) {
            return toString;
        }
        int length = toString.length();
        int index = toString.indexOf('@');
        if (index > 2) {
            return toString.charAt(0) + StarUtil.getStar(index - 2) + toString.substring(index - 1, length);
        } else if (index > 0) {
            return StarUtil.getStar(index) + toString.substring(index, length);
        } else if (index == 0) {
            return toString;
        } else {
            return toString;
        }
    }
}
